export default {
    data() {
        return {
            storeList: [{
                storeName: "全部",
                deviceList: []
            }],
            stockList: [], // 库存列表
            storeIndex: 0, // 门店索引
            deviceIndex: 0, // 设备索引
            storeSelectShow: false, // 门店选择下拉显示
            deviceSelectShow: false, // 设备选择下拉显示
            page: 1, // 当前页码
            noMore: true, // 没有更多了
        }
    },
    onLoad() {
        console.log("记录id", this.$store.state.activityRecordId);
        const _this = this
        // setTimeout(function(){
        _this.getDeviceList();
        // }, 2000)
    },
    onReachBottom() {
        if (this.noMore) return false;
        this.page++;
    },
    methods: {
        // 获取库存列表
        getStockList: function() {
            let data = {
                deviceId: this.storeList[this.storeIndex].deviceList[this.deviceIndex].id,
                // activityId: this.$store.state.activityRecordId  // 查询记录Id
            }
            this.$util.request(this.$api.GetStockList, data).then(res => {
                if (res.returnCode == "SUCCESS") {
                    res.data.stockDetails = res.data.stockDetails || [];
                    if (this.page == 1) this.stockList = [];
                    res.data.stockDetails.forEach((item, index) => {
                        item.currentCount = item.count;
                        item.standardCount = item.baseCount;
                        item.lackCount = (item.baseCount || 0) - (item.count || 0);
                        item.name = item.name;
                        item.sell = item.sell;
                        this.stockList.push(item);
                    })
                } else {
                    uni.showToast({
                        title: res.returnMessage,
                        icon: "none"
                    });
                }
            })
        },
        // 获取已绑定的设备列表
        getDeviceList: function() {
            const userId = this.$store.state.userInfo.userId.toString()
            let data = {
                userId: userId,
                pageNo: 1,
                pageSize: 100,
            }
            this.$util.request(this.$api.GetBindDeviceList, data, "POST").then(res => {
                if (res.returnCode == "SUCCESS") {
                    res.data = res.data || [];
                    if (this.page == 1) this.stockList = [];
                    res.data.forEach((item, index) => {
                        console.log(item)
                        console.log(this.storeList[0].deviceList)
                        this.storeList[0].deviceList.push(item);
                    })
                    this.getStockList(); // 获取库存列表
                } else {
                    uni.showModal({
                        title: '提示',
                        content: res.returnMessage,
                        showCancel: false,
                    });
                }
            })
        },
        // 点击进入个人中心
        personal: function() {
            uni.navigateTo({
                url: '/pages/mine/mine'
            });
        },
        // 首页点击
        home: function() {
            uni.redirectTo({
                url: '/pages/indexManage/indexManage',
            });
        },

        // 上货库存
        stock: function() {
            uni.redirectTo({
                url: '../stock/stock'
            });
        },

        // 上货记录
        record: function() {
            uni.redirectTo({
                url: '../record/record'
            });
        },

        // 设备下拉选择
        deviceSelect: function(index) {
            this.deviceIndex = index;
            this.storeSelectShow = false;
            this.deviceSelectShow = false;
            this.stockList = [];
            this.getStockList();
        }
    }
}